clc;
clear;

format short

tic;
startTime = cputime;
pde = PDE_struct_2d(1);
left = -1;
right = 1;
bottom = -1;
top = 1;
vector_N = [2];

basis_type = "P1";

% figure;
% plot_basis_function_2d(basis_type);
% figure;
% plot_basis_points_2d(basis_type);

error_L2 = zeros(size(vector_N,2),1);
error_H1 = zeros(size(vector_N,2),1);

for i = 1:size(vector_N,2)
    Nx = vector_N(i);
    Ny = Nx;

    mesh = Mesh_struct_2d(left, right, bottom, top, Nx, Ny, basis_type);

    figure;
    plot_node_elem_edge_2d(mesh.node, mesh.elem, basis_type);

    U = poisson_solver_2d(mesh, pde);

    error_L2(i,1) = process_error_2d(mesh.node, mesh.elem, mesh.basis_type, pde, U, "L2");
    error_H1(i,1) = process_error_2d(mesh.node, mesh.elem, mesh.basis_type, pde, U, "H1");

    fprintf("完成%d/%d次\n", i, size(vector_N,2));
end

process_convergence_rate_2d(error_L2, vector_N);
process_convergence_rate_2d(error_H1, vector_N);

elapsedTOCTime = toc;
elapsedCPUTime = cputime - startTime;
disp(['Elapsed TOC time is ', num2str(elapsedTOCTime), ' seconds.']);
disp(['Elapsed CPU time is ', num2str(elapsedCPUTime), ' seconds.']);

